package view
{

	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.setTimeout;
	
	import model.DataBar;
	import model.Image;
	
	public class Cannon extends Sprite
	{
		private var image:Image;
		//注册点偏移量
		public var cannonW:Number;
		public var cannonH:Number;
		/**
		 *震动幅度 
		 */		
		public var cannonD:uint = 50;
		
		public function Cannon()
		{
			super();
			image = new Image( "assets/炮筒.png");			
			image.addEventListener(Image.COMPLETE,onComplete);	
			this.addChild(image);
		}
		
		private function onComplete(event:Event):void
		{
			image.removeEventListener(Image.COMPLETE,onComplete);
			var bit:Bitmap = image.loader.content as Bitmap;
			bit.smoothing = true;
			
			
			cannonW = image.width / 2;
			cannonH = image.height / 2 + 35;
			DataBar.cannonHeight = cannonH + 18;
			image.x = -cannonW;
			image.y = -cannonH;
			event.currentTarget.removeEventListener(Image.COMPLETE,onComplete)
			dispatchEvent(new Event(Image.COMPLETE));
		}
		
		
		//震动
		private var seismism:uint = 4;
		public function onFire():void
		{
			image.y = -cannonH + seismism;
			setTimeout(fire,cannonD);
						
		}
		private function fire():void
		{
			image.y = -cannonH;
		}
		
	}
}